package com.saascloud.idempotent.config;

import com.saascloud.idempotent.core.aspect.NoRepeatSubmitAop;
import com.saascloud.idempotent.core.expression.ExpressionResolver;
import com.saascloud.idempotent.core.expression.KeyResolver;
import com.saascloud.redis.config.SaasRedisAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @Author: liangxu
 * @Contact: one_dream@aliyun.com
 * @Date: 2022/5/24 11:08
 * @Version: 1.0
 * @Description:
 */
@AutoConfigureAfter(SaasRedisAutoConfiguration.class)
public class IdempotentSAutoConfiguration {

    @Bean
    @ConditionalOnBean(RedisTemplate.class)
    public NoRepeatSubmitAop noRepeatSubmitAop() {
        return new NoRepeatSubmitAop();
    }

    /**
     * key 解析器
     *
     * @return KeyResolver
     */
    @Bean
    @ConditionalOnMissingBean(KeyResolver.class)
    public KeyResolver keyResolver() {
        return new ExpressionResolver();
    }

}
